﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.Core.DomainModel;

namespace MethodWorx.CMS.Content
{
    [Serializable]
    public class PageTemplateConstraint : Entity
    {
        public virtual PageTemplate RelatedTemplate { get; set; }
        public int? MinimumRequired { get; set; }
        public int? MaximumAllowed { get; set; }
        public string NameConstraint { get; set; }

        public override string ToString()
        {
            string name;
            string minimumRequired;
            string maximumAllowed;

            if(MinimumRequired.HasValue)
                minimumRequired = MinimumRequired.ToString();
            else
                minimumRequired = "n";

            if(MaximumAllowed.HasValue)
                maximumAllowed = MaximumAllowed.ToString();
            else
                maximumAllowed = "n";

            name = string.Format("{0} {1}..{2} Name={3}", this.RelatedTemplate.Name,
                                 minimumRequired, maximumAllowed, this.NameConstraint);

            return name;
        }

        public string GetConstraintDisplayString()
        {
            string name;
            string minimumRequired;
            string maximumAllowed;

            if (MinimumRequired.HasValue)
                minimumRequired = MinimumRequired.ToString();
            else
                minimumRequired = "n";

            if (MaximumAllowed.HasValue)
                maximumAllowed = MaximumAllowed.ToString();
            else
                maximumAllowed = "n";

            if (string.IsNullOrEmpty(this.NameConstraint))
            {
                name = string.Format("{0}..{1}",
                                     minimumRequired, maximumAllowed);
            }
            else
            {
                name = string.Format("{0}..{1} Name={2}",
                                     minimumRequired, maximumAllowed, this.NameConstraint);
            }

            return name;
        }
    }
}
